<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<body>
<form id="form">
    <input type="hidden" id="id" name="id">
    name: <input type="text" id="name" name="name"> <br>
    money: <input type="text" id="money" name="money"> <br>

    <input type="button" value="更新" id="update">
</form>
</body>
<script>
    let aid = location.search.split("=")[1];

    let url = "/account/"+aid;

    $.get(url,{},function (r){
        let code = r.code;
        if (code == 1000){
            //成功 - 回显
            let account = r.data;
            $("#id").val(account.id);
            $("#name").val(account.name);
            $("#money").val(account.money);
        }else{
            alert(r.msg)
        }
    },"json");

    $("#update").click(function (){
        //获取数据
        let id = $("#id").val();
        let name = $("#name").val();
        let money = $("#money").val();

        // let params = {
        //     id:id,
        //     name:name,
        //     money:money
        // }

        let params = $("#form").serialize();

        //发送put请求实现更新 (数据携带方式是通过url以key=value形式携带的)
        $.ajax({
            url:"/account?"+params,
            type:"PUT",
            success:function (r){
                if (r.code == 1000){
                    location.href = "index.html"
                }else{
                    alert(r.msg)
                }
            },
            dataType:"json"
        })
    });

</script>
</html>